 var page_chat_iscroll,
     page_tobutyit_iscroll,
     page_notice,
     page_photo_album,
     page_loginInside,
     page_fogetInside,
     page_registerInside,
     page_addressInside,
     page_newadInside,
     page_selectunivsInside,
     page_change_userpic,
     page_selectschoolInside,
     page_inputName,
     page_inputMajor,
     page_inputNote,
     page_inputAddress,
     page_publish,
     Page_example;
 var he_count = 1;
 var picserver_index = "http://infinitus.com2.z0.glb.clouddn.com/",
     server_index = "http://api.infinitus.com.cn/api/",
     notification_total_index = 'notification_total.vm',
     friend_total_index = 'total.vm',
     notification_chat_total_index = 'notification_chat_total.vm',
     message_get_index = 'message_get.vm',
     image80jpg_index = "?imageView2/1/h/80/w/80/format/jpg/interlace/1";

 // 导入cordova
 // window.cordova = require('cordova');
 // 启动处理
 // require('cordova/init');

 var u = navigator.userAgent,
     app = navigator.appVersion;
 if (typeof(cordova) == "undefined") {
     window.isDesktop = true;
     window.isAndroid = false;
     window.isiOS = false;
     // window.prompt = function() {
     //     return false;
     // };
 } else {
     window.isDesktop = false;
     window.isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
     window.isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
 }

 function onDeviceReady() {
     console.log("onDeviceReady");
console.log("platform is WIN(%s),Android(%s),iOS(%s)",window.isDesktop,window.isAndroid,window.isiOS);
     document.addEventListener("menubutton", onMenuKeyDown, false);
     document.addEventListener("backbutton", onBackKeyDown, false);
     document.addEventListener("resume", onResume, false);
     document.addEventListener("pause", onPause, false);
     document.addEventListener("searchbutton", onSearchKeyDown, false);
 }
 
 function onMenuKeyDown() {
     console.log("onMenuKeyDown");
     receiveMessage("title01", "only test", "extra01", "msgId01");
 }

 function onBackKeyDown() {
     console.log("onBackKeyDown");
 }

 function onResume() {

     // localStorage.setItem('index_is_refresh', true);

     Page_example.getImgNum();

     console.log("onResume");

 }

 function onPause() {
     console.log("onPause");
     // localStorage.setItem('index_is_refresh', true);
 }

 function onSearchKeyDown() {
     console.log("onSearchKeyDown");
 }

 function onLoad() {
     console.log("onLoad");
     document.addEventListener("deviceready", onDeviceReady, false);
 }

 
 function exitApp() {
     navigator.app.exitApp();
 }

 function onBackKey() {
     document.removeEventListener("backbutton", onBackKey, false); // 注销返回键 
     window.history.back();
 }

 function backToChangeInfo() {
     document.removeEventListener("backbutton", backToChangeInfo, false); // 注销返回键 
     window.butterfly.navigate('com.52zzb.main/changeInfo', {
         trigger: true
     });
 }

 function backToIndex() {
     document.removeEventListener("backbutton", backToIndex, false); // 注销返回键 
     document.removeEventListener("backbutton", onBackKey, false); // 注销返回键 
     document.addEventListener("backbutton", onDoubleKey, false); //返回键
     $("#bottom_control").show();
     $(".main_nav_active").removeClass('main_nav_active');
     $("#home").addClass('main_nav_active');

     window.butterfly.navigate('com.52zzb.main/index', {
         trigger: true
     });
 }

 function onDoubleKey() {
     var Toast = function(msg, duration) {
         duration = isNaN(duration) ? 1000 : duration;
         var m = document.createElement('div');
         m.innerHTML = msg;
         m.style.cssText = "padding:10px 0;width:60%; min-width:150px; background:rgba(0,0,0,0.5); color:#fff; line-height:20px; text-align:center; border-radius:5px; position:fixed; bottom:10%; left:20%; z-index:999999; font-weight:bold;";
         document.body.appendChild(m);
         setTimeout(function() {
             var d = 0.5;
             m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
             m.style.opacity = '0';
             setTimeout(function() {
                 document.body.removeChild(m);
             }, d * 1000);
         }, duration);
     };
     Toast('再点击一次退出!');
     document.removeEventListener("backbutton", onDoubleKey, false); // 注销返回键 
     document.addEventListener("backbutton", exitApp, false); //绑定退出事件 
     // 3秒后重新注册 
     var intervalID = window.setInterval(function() {
         window.clearInterval(intervalID);
         document.removeEventListener("backbutton", exitApp, false); // 注销返回键 
         document.addEventListener("backbutton", onDoubleKey, false); // 返回键 
     }, 2000);
 }
 document.getElementsByTagName('html')[0].style.fontSize = document.documentElement.clientWidth / 3 + 'px';
 // window.localStorage.setItem('clientWidth', 400); //存储屏幕宽度
 // window.localStorage.removeItem("clientWidth");
 var appVersion = window.navigator.appVersion;
 var N918St = appVersion.indexOf('N918St') > -1; //判断是否是 中兴V5S 系统给出的屏幕宽度是360
 var Y29L = appVersion.indexOf('Y29L') > -1; //判断是否是 vivo Y29L
 if (N918St) { //如果是中兴V5S 把屏幕宽度设置为400；
     document.getElementsByTagName('html')[0].style.fontSize = 400 / 3 + 'px';

     window.localStorage.setItem('clientWidth', 400); //存储屏幕宽度
 }
 if (Y29L) {
     document.getElementsByTagName('html')[0].style.fontSize = 400 / 3 + 'px';
     window.localStorage.setItem('clientWidth', 400);
 }
 var adaptUILayout = function(uiWidth) { //兼容三星代码
     var
         isI9300,
         deviceWidth,
         devicePixelRatio,
         targetDensitydpi,
         meta,
         initialContent;
     //获取设备信息,并矫正参数值
     appVersion = window.navigator.appVersion;
     var isI9300 = appVersion.indexOf('GT-I9300') > -1;
     if (isI9300) {
         devicePixelRatio = window.devicePixelRatio;
         deviceWidth = window.screen.width;
         //在三星 I9300G上, screen.width值不不一定等于屏幕分辨率
         //获取最终dpi
         targetDensitydpi = uiWidth / deviceWidth * devicePixelRatio * 160;
         initialContent = 'target-densitydpi=' + targetDensitydpi + ', width=device-width, user-scalable=no';
         //添加到meta viewport
         meta = document.getElementsByName('viewport')[0];
         meta.setAttribute('content', initialContent);
         document.getElementsByTagName('html')[0].style.fontSize = uiWidth / 3 + 'px';
     }
 };
 adaptUILayout(360);
